package com.xsqf.jt808.common.vo.req.server;

import com.xsqf.jt808.common.config.ParameterId;
import com.xsqf.jt808.common.util.BitOperator;
import com.xsqf.jt808.common.vo.DataPacket;
import io.netty.buffer.ByteBuf;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * ParameterSetting
 * 设置终端参数
 *
 * @author
 * @date 2020/5/26 15:22
 */
@Data
@ApiModel(value = "设置终端参数")
public class ParameterSetting extends DataPacket {

    @ApiModelProperty(value = "参数总数")
    private Integer total;

    @ApiModelProperty(value = "参数项列表")
    private List<TerminalParameter> parameters;

    @Override
    public ByteBuf toByteBufMsg() {
        ByteBuf bb = super.toByteBufMsg();
        bb.writeByte(total);
        for (TerminalParameter p : parameters
        ) {
            ParameterId idType = p.getIdType();
            Integer i = idType.value;
            bb.writeBytes(BitOperator.int2bytes(i, 4));
            bb.writeByte(p.getLength());
            bb.writeBytes(BitOperator.int2bytes(p.getBytesValue(), p.getLength()));
        }

        return bb;
    }

}
